package com.glasses.abc.view;

import com.glasses.abc.business.ReportMenuItem;
import com.glasses.abc.business.Report;
import com.glasses.abc.data.Mock;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;

/**
 *
 * @author Jean-Luc Burot
 * @since 2014-10-13
 */
@ManagedBean
public class ReportService {
    private long id;
    private Report report;
    
    public long getId() {
        return this.id;
    }
    
    public void setId(long id) {
        System.out.println("Report.setId(" + id + ") triggered.");
        this.id = id;
        this.report = null;
    }
    
    public List<ReportMenuItem> getCityTree() {
        return Mock.getCityTree();
    }
    
    public String getContent() {
        System.out.println("Report.getContent() triggered.");
        if(report == null) {
            if(loadReport() == false)
                return "No content!";
        }
        
        return this.report.getReportContent();
    }
    
    public String getCaption() {
        System.out.println("Report.getCaption() triggered.");
        if(report == null) {
            if(loadReport() == false)
                return "No content!";
        }
        
        return this.report.getReportCaption();
    }
    
    public Date getCreated() {
        System.out.println("Report.getCreated() triggered.");
        if(report == null) {
            if(loadReport() == false)
                return null;
        }
        
        return this.report.getTimeLog().getCreated();
    }
    
    public Date getModified() {
        System.out.println("Report.getModified() triggered.");
        if(report == null) {
            if(loadReport() == false)
                return null;
        }
        
        return this.report.getTimeLog().getModified();
    }
    
    public String getAuthor() {
        System.out.println("Report.getCaption() triggered.");
        if(report == null) {
            if(loadReport() == false)
                return "No content!";
        }
        
        return this.report.getAuthor().toString();
    }
    
    private boolean loadReport() {
        System.out.println("Report.loadReport() triggered.");
        this.report = Mock.getReport(this.id);
        return this.report != null;
    }
}
